<template>
  <div>
    <!--查询区域-->
    <div class="jeecg-basic-table-form-container">
      <a-form @keyup.enter.native="reload" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-row :gutter="24">
          <a-col :lg="8">
            <a-form-item label="支付周期">
              <a-date-picker v-model:value="queryParam.payDate" picker="month" placeholder="请选择支付周期" />
            </a-form-item>
          </a-col>
          <a-col :lg="8">
            <a-form-item label="结算周期">
              <a-date-picker v-model:value="queryParam.date" picker="month" placeholder="请选择支付周期" />
            </a-form-item>
          </a-col>
          <a-col :lg="8">
            <a-form-item label="结算对象">
              <j-dict-select-tag v-model:value="queryParam.type" dictCode="ZQLX" placeholder="请选择结算对象" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-col :lg="6">
                <a-button type="primary" preIcon="ant-design:search-outlined" @click="reload">查询</a-button>
                <a-button preIcon="ant-design:reload-outlined" @click="searchReset" style="margin-left: 8px">重置</a-button>
              </a-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
      <BasicTable @register="registerTable">
        <!--插槽:table标题-->
        <template #tableTitle>
          <!-- <a-button  type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
          <j-upload-button  type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">导入</j-upload-button> -->
        </template>
        <!--操作栏-->
        <template #action="{ record }">
          <TableAction :actions="getTableAction(record)" :style="{ width: 200 }" />
        </template>
      </BasicTable>
  </div>
</template>

<script lang="ts" name="InsuranceSettlementInfo-insuranceSettlementInfo" setup>
  import { ref, reactive } from 'vue';
  import { BasicTable, TableAction } from '/@/components/Table';
  import { dateFormat } from '/@/utils/common/compUtils';
  import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns } from './settlementInfo.data';
  import { useRouter } from 'vue-router';
  import { useMethods } from '/@/hooks/system/useMethods';
  import { list,getExportUrl } from './settlementInfo.api';
  import dayjs from 'dayjs';


  const queryParam = ref<any>({
    date: dayjs().add(-1,'month'),
    type: 'INSURANCE'
  });
  const router = useRouter();
  const confirmLoading = ref<boolean>(false);
  const { handleExportXls } = useMethods();
  //注册table数据
  const { tableContext } = useListPage({
    tableProps: {
      title: 'insurance_settlement_info',
      api: list,
      columns,
      canResize: false,
      useSearchForm: false,
      actionColumn: {
        width: 250,
        fixed: 'right',
      },
      beforeFetch: (params) => {
        const date = dateFormat(queryParam.value.date, 'yyyy-MM');
        const payDate = dateFormat(queryParam.value.payDate, 'yyyy-MM');
        return Object.assign(params, {
          date,
          payDate,
          pageIndex: params.pageNo,
          type: queryParam.value.type,
        });
      },
    },
    exportConfig: {
      name: 'insurance_settlement_info',
      url: getExportUrl,
    },
  });
  const [registerTable, { reload }] = tableContext;
  const labelCol = reactive({
    xs: { span: 24 },
    sm: { span: 7 },
  });
  const wrapperCol = reactive({
    xs: { span: 24 },
    sm: { span: 16 },
  });
  // onMounted(() => {
  //   const payBegin = dayjs().startOf('month');
  //   queryParam.value.date = payBegin;
  // });


  /**
   * 操作栏
   */
  function getTableAction(record) {

    return [
      {
        label: '保单明细',
        onClick: () => {
          let  type = queryParam.value.type;
          console.info(queryParam);
          handleExportXls('保单明细', `/settlementMange/exportXlsPolicyInfo?date=${record.date}&name=${record.name}`+"&type="+type);
          // window.open();
        },
      },
    ];
  }


  /**
   * 重置
   */
  function searchReset() {
    queryParam.value = {};
    //刷新数据
    reload();
  }

  /**
   * 成功回调
   */
  function handleSuccess() {
    reload();
  }

  /**
   * 查询
   */
  function searchQuery() {
    reload();
  }
</script>

<style lang="less" scoped>
.jeecg-basic-table-form-container {
  .table-page-search-submitButtons {
    display: block;
    margin-bottom: 24px;
    white-space: nowrap;
  }
  .query-group-cust {
    width: calc(50% - 15px);
    min-width: 100px !important;
  }
  .query-group-split-cust {
    width: 30px;
    display: inline-block;
    text-align: center;
  }
}
</style>
